<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #cover="{ record }">
        <a-avatar shape="square">
          <img :src="record.cover?record.cover:'/nopic.png'" style="object-fit: cover" />
        </a-avatar>
      </template>

      <template #amount_price="{ record }">
        {{ tool.toFixed(record.zbt_remote_price*6.5, 2, 1) }}
      </template>
      <template #autoDeliverQuantity="{ record }">
        {{record.autoDeliverQuantity}}/{{record.manualQuantity}}
      </template>

      <template #create_time="{ record }">
        {{ tool.dateFormat(record.create_time, 'yyyy-MM-dd hh:mm:ss', '-') }}
      </template>

      <template #up_status="{ record }">
        <a-switch
            :checked-value="1"
            unchecked-value="2"
            @change="switchStatus($event, record.id,'up_status')"
            :default-checked="record.up_status == 1"
        />
      </template>


      <template #status="{ record }">
        <a-switch
            :checked-value="1"
            unchecked-value="2"
            @change="switchStatus($event, record.id,'status')"
            :default-checked="record.status == 1"
        />
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import configProduct from '@/api/config/configProduct'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  configProduct.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  configProduct.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'us_config_product',
  pk: 'id',
  operationColumn: false,
  operationColumnWidth: 160,
  bordered:{ wrapper: true, cell: true },
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: configProduct.getZbtIndex,
  recycleApi: configProduct.getRecycleList,

})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    width:80,
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "产品名称",
    dataIndex: "name",
    width:280,
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入产品名称"
    }
  },
  {
    title: "商品图片",
    dataIndex: "cover",
    formType: "input"
  },
  {
    title: "CS2DT当前售价",
    dataIndex: "zbt_remote_price",
    formType: "input",
    width:220,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "CS2DT人民币售价",
    dataIndex: "amount_price",
    formType: "input",
    width:220,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "U9当前售价",
    dataIndex: "price",
    formType: "input",
    width:220,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "人工发货/自动发货",
    dataIndex: "autoDeliverQuantity",
    formType: "input",
    width:220,
    addDisplay: false,
    editDisplay: false
  },


])
</script>
<script> export default { name: 'config:product' } </script>